package com.yifeng.repo.base.mdm.console.impl;

import com.yifeng.base.bds.api.store.StoreMasterDataRestService;
import com.yifeng.base.bds.api.store.dto.*;
import com.yifeng.base.bds.api.store.params.StoreInfoParam;
import com.yifeng.repo.base.mdm.loader.annotation.MdmCache;
import com.yifeng.repo.base.params.ConsoleParam;
import com.yifeng.repo.base.security.proxy.CommonProxy;
import com.yifeng.repo.base.utils.codec.URLEncodeHelper;
import com.yifeng.repo.base.utils.converter.DateHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by daibing on 2024/1/30.
 */
@MdmCache(mdmTypeCode = "store")
public class StoreMasterDataRestServiceImpl extends CommonProxy implements StoreMasterDataRestService {
    private final String mapping;

    public StoreMasterDataRestServiceImpl(ConsoleParam consoleParam) {
        super(consoleParam);
        this.mapping = "/yfcloud/bds/rest/StoreMasterDataRestService";
    }

    @Override
    public List<StoreCoreInfoDto> listCoreInfo(StoreInfoParam param) {
        String url = consoleParam.getUrl() + mapping + "/listCoreInfo";
        Map<String, String> params = new HashMap<>(8);
        params.put("storeStatus", param.getStoreStatus() != null ? param.getStoreStatus().getCode() : null);
        params.put("endTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getEndTime())));
        params.put("offsetTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getOffsetTime())));
        params.put("provinceCode", param.getProvinceCode());
        params.put("cityCode", param.getCityCode());
        params.put("countyCode", param.getCountyCode());
        params.put("edifactCompanyCode", param.getEdifactCompanyCode());
        params.put("offsetStoreCode", param.getOffsetStoreCode());
        params.put("pageSize", String.valueOf(param.getPageSize()));
        String queryParameters = buildQueryParameters(params);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreCoreInfoDto.class);
    }

    @Override
    public StoreBaseInfoDto getBaseInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getBaseInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreBaseInfoDto.class);
    }

    @Override
    public List<StoreBaseInfoDto> listBaseInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listBaseInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreBaseInfoDto.class);
    }

    @Override
    public StoreDetailInfoDto getDetailInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getDetailInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreDetailInfoDto.class);
    }

    @Override
    public List<StoreDetailInfoDto> listDetailInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listDetailInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreDetailInfoDto.class);
    }

    @Override
    public StoreAddressInfoDto getAddressInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getAddressInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreAddressInfoDto.class);
    }

    @Override
    public List<StoreAddressInfoDto> listAddressInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listAddressInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreAddressInfoDto.class);
    }

    @Override
    public StoreBusinessInfoDto getBusinessInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getBusinessInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreBusinessInfoDto.class);
    }

    @Override
    public List<StoreBusinessInfoDto> listBusinessInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listBusinessInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreBusinessInfoDto.class);
    }

    @Override
    public StorePlaceInfoDto getPlaceInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getPlaceInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StorePlaceInfoDto.class);
    }

    @Override
    public List<StorePlaceInfoDto> listPlaceInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listPlaceInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StorePlaceInfoDto.class);
    }

    @Override
    public StoreFinanceInfoDto getFinanceInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getFinanceInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreFinanceInfoDto.class);
    }

    @Override
    public List<StoreFinanceInfoDto> listFinanceInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listFinanceInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreFinanceInfoDto.class);
    }

    @Override
    public StoreMedicareInfoDto getMedicareInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getMedicareInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreMedicareInfoDto.class);
    }

    @Override
    public List<StoreMedicareInfoDto> listMedicareInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listMedicareInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreMedicareInfoDto.class);
    }

    @Override
    public StoreSupplyInfoDto getSupplyInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getSupplyInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreSupplyInfoDto.class);
    }

    @Override
    public List<StoreSupplyInfoDto> listSupplyInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listSupplyInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreSupplyInfoDto.class);
    }

    @Override
    public StoreRegistrationInfoDto getRegistrationInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getRegistrationInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreRegistrationInfoDto.class);
    }

    @Override
    public List<StoreRegistrationInfoDto> listRegistrationInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listRegistrationInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreRegistrationInfoDto.class);
    }

    @Override
    public List<StoreCustomInfoDto> listStoreCustomInfo(StoreInfoParam param) {
        String url = consoleParam.getUrl() + mapping + "/listStoreCustomInfo";
        Map<String, String> params = new HashMap<>(8);
        params.put("storeStatus", param.getStoreStatus() != null ? param.getStoreStatus().getCode() : null);
        params.put("endTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getEndTime())));
        params.put("offsetTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getOffsetTime())));
        params.put("offsetStoreCode", param.getOffsetStoreCode());
        params.put("pageSize", String.valueOf(param.getPageSize()));
        params.put("provinceCode", param.getProvinceCode());
        params.put("cityCode", param.getCityCode());
        params.put("countyCode", param.getCountyCode());
        String queryParameters = buildQueryParameters(params);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreCustomInfoDto.class);
    }

    @Override
    public List<StoreCorporationRegionInfoDto> listCorporationRegionInfo(StoreInfoParam param) {
        String url = consoleParam.getUrl() + mapping + "/listCorporationRegionInfo";
        Map<String, String> params = new HashMap<>(8);
        params.put("storeStatus", param.getStoreStatus() != null ? param.getStoreStatus().getCode() : null);
        params.put("endTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getEndTime())));
        params.put("offsetTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getOffsetTime())));
        params.put("offsetStoreCode", param.getOffsetStoreCode());
        params.put("pageSize", String.valueOf(param.getPageSize()));
        params.put("provinceCode", param.getProvinceCode());
        params.put("cityCode", param.getCityCode());
        params.put("countyCode", param.getCountyCode());
        String queryParameters = buildQueryParameters(params);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreCorporationRegionInfoDto.class);
    }

    @Override
    public StoreInShopInfoDto getInShopInfo(String storeCode) {
        String url = consoleParam.getUrl() + mapping + "/getInShopInfo";
        String queryParameters = buildSingleQueryParameters("storeCode", storeCode);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doGetCallByRpc(requestUrl, StoreInShopInfoDto.class);
    }

    @Override
    public List<StoreInShopInfoDto> listInShopInfo(List<String> storeCodes) {
        String url = consoleParam.getUrl() + mapping + "/listInShopInfo";
        String queryParameters = buildCollectionQueryParameters("storeCodes", storeCodes);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreInShopInfoDto.class);
    }

    @Override
    public List<StoreSiteSelectionBindInfoDto> listSiteSelectionBindInfoBySiteApplyNos(List<String> siteApplyNos) {
        String url = consoleParam.getUrl() + mapping + "/listSiteSelectionBindInfoBySiteApplyNos";
        String queryParameters = buildCollectionQueryParameters("siteApplyNos", siteApplyNos);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreSiteSelectionBindInfoDto.class);
    }

    @Override
    public List<StoreCoreInfoDto> listStoreCoreInfoByEdifactCompanyCode(StoreInfoParam param) {
        String url = consoleParam.getUrl() + mapping + "/listStoreCoreInfoByEdifactCompanyCode";
        Map<String, String> params = new HashMap<>(8);
        params.put("storeStatus", param.getStoreStatus() != null ? param.getStoreStatus().getCode() : null);
        params.put("endTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getEndTime())));
        params.put("offsetTime", URLEncodeHelper.encode(DateHelper.getDateTime(param.getOffsetTime())));
        params.put("offsetStoreCode", param.getOffsetStoreCode());
        params.put("pageSize", String.valueOf(param.getPageSize()));
        params.put("provinceCode", param.getProvinceCode());
        params.put("cityCode", param.getCityCode());
        params.put("countyCode", param.getCountyCode());
        params.put("edifactCompanyCode", param.getEdifactCompanyCode());
        String queryParameters = buildQueryParameters(params);
        String requestUrl = String.format("%s?%s", url, queryParameters);
        return this.doListCallByRpc(requestUrl, StoreCoreInfoDto.class);
    }
}
